
package poker.plans.player.betting;

import jadex.runtime.Plan;
import jadex.runtime.ICandidateInfo;

import poker.PokerConstants;
import poker.beliefs.Money;


public class ChooseBettingPlanPlan extends Plan {

	private static final int LOWER_LIMIT_CREDITS = 80;
	private static final int UPPER_LIMIT_CREDITS = 100;
	
	
	public void body() {
		
		System.out.println("PLAYER " + getAgentName() + ": Meta-level -> Choosing betting plan");
		
		int strategy = (Integer)getBeliefbase().getBelief("strategy").getFact();
		int currentMoney = ((Money)getBeliefbase().getBelief("money").getFact()).getMoney();
		String kind;
		switch (strategy) {
			case PokerConstants.STRATEGY_CONSERVATIVE:
				// If we have enough money, we can try a more risky strategy
				if (currentMoney > UPPER_LIMIT_CREDITS)
					kind = "aggressive";
				else
					kind = "conservative";
				break;
			case PokerConstants.STRATEGY_AGGRESSIVE:
				// We choose the aggressive betting only if we have enough money
				if (currentMoney < LOWER_LIMIT_CREDITS)
					kind = "conservative";
				else
					kind = "aggressive";
				break;
			case PokerConstants.STRATEGY_BLUFFER:
				kind = "bluffer";
				break;
			default:
				kind = "conservative";
				break;
		}
		
		ICandidateInfo[] apps = (ICandidateInfo[])getParameterSet("applicables").getValues();
		ICandidateInfo sel = null;
		for (ICandidateInfo app : apps) {
			if (app.getPlan().getName().startsWith(kind + "_betting_plan"))
				sel = app;
		}
		
		getParameterSet("result").addValue(sel);
	}
	
	
}
